home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libpod / lstatus.c.z / lstatus.c
C/C++ Source or Header  |  1996-05-06  |  8KB  |  289 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1992 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: lstatus.c
  27.  *
  28.  * Description: Sample program that demonstrates the use of the local
  29.  *    form of the libpod status read and write functions.
  30.  *
  31.  *    Usage: lstatus printer_name [op_status]
  32.  *
  33.  *    If op_status is specified, an attempt is made to write the
  34.  *    new operational status to the printer POD status file. The
  35.  *    status before and after the write are displayed.
  36.  *
  37.  *    If op_status is not specified, the current status is displayed.
  38.  *
  39.  *    Note: You must have root or lp permissions to successfully run
  40.  *    this program to write the status file. There is no such
  41.  *    restriction on reading the status file.
  42.  *
  43.  **************************************************************************/
  44.  
  45.  
  46. #ident "$Revision: 1.4 $"
  47.  
  48.  
  49. #include <stdio.h>
  50. #include <string.h>
  51. #include <stdlib.h>
  52. #include <time.h>
  53. #include <pod.h>
  54.  
  55.  
  56. #define HANDLE_ERROR(pname)    { \
  57.                 PDPerror(pname); \
  58.                 exit(1); \
  59.                 }
  60.  
  61.  
  62. void usage(char*);
  63. void disp_opstatus(int);
  64. void disp_status(PDStatusStruct*, PDMessageStruct*);
  65. void disp_colorspace(int);
  66. void disp_depth(int);
  67. void disp_format(int);
  68.  
  69.  
  70. int main(int argc, char **argv)
  71. {
  72.     int opstatus;
  73.     PDStatusStruct *status;
  74.     PDMessageStruct *messages;
  75.     time_t mod_time;
  76.  
  77.     /*
  78.      * Get the printer name from command line
  79.      */
  80.     if (argc < 2) {
  81.     usage(argv[0]);
  82.     exit(1);
  83.     }
  84.  
  85.     /*
  86.      * Handle status change request
  87.      */
  88.     if (argc == 3) {
  89.         /*
  90.          * Read and display original operational status
  91.          */
  92.         if (PDLocalReadOpStatus(argv[1], &opstatus, &mod_time) < 0)
  93.         HANDLE_ERROR(argv[0]);
  94.         (void)printf("Original status summary - last modified %s\n",
  95.                             ctime(&mod_time));
  96.         disp_opstatus(opstatus);
  97.         (void)printf("\n");
  98.  
  99.         /*
  100.          * Read and display the original full status and message information
  101.          */
  102.         if (PDLocalReadStatus(argv[1], &status, &messages, &mod_time) < 0)
  103.         HANDLE_ERROR(argv[0]);
  104.         (void)printf("Original complete status - last modified %s\n",
  105.                             ctime(&mod_time));
  106.         disp_status(status, messages);
  107.         (void)printf("\n");
  108.  
  109.     /*
  110.      * Now attempt to set a new status
  111.      */
  112.     (void)printf("Attempting to set operational status to: %s\n\n",
  113.                                 argv[2]);
  114.     if (!strcasecmp(argv[2], "busy"))
  115.         status->operational_status = PD_STATUS_BUSY;
  116.     else if (!strcasecmp(argv[2], "idle"))
  117.         status->operational_status = PD_STATUS_IDLE;
  118.     else if (!strcasecmp(argv[2], "faulted"))
  119.         status->operational_status = PD_STATUS_FAULTED;
  120.     else if (!strcasecmp(argv[2], "unavailable"))
  121.         status->operational_status = PD_STATUS_UNAVAILABLE;
  122.     else {
  123.         (void)fprintf(stderr, "Unknown status '%s' specified\n", argv[2]);
  124.         status->operational_status = -1;
  125.     }
  126.     if (status->operational_status >= 0)
  127.         if (PDLocalWriteStatus(argv[1], status, messages) < 0)
  128.             HANDLE_ERROR(argv[0]);
  129.     }
  130.  
  131.     /*
  132.      * Read and display only operational status
  133.      */
  134.     if (PDLocalReadOpStatus(argv[1], &opstatus, &mod_time) < 0)
  135.     HANDLE_ERROR(argv[0]);
  136.     (void)printf("Current status summary - last modified %s\n",
  137.                             ctime(&mod_time));
  138.     disp_opstatus(opstatus);
  139.     (void)printf("\n");
  140.  
  141.     /*
  142.      * Read and display the full status and message information
  143.      */
  144.     if (PDLocalReadStatus(argv[1], &status, &messages, &mod_time) < 0)
  145.     HANDLE_ERROR(argv[0]);
  146.     (void)printf("Current complete status - last modified %s\n",
  147.                             ctime(&mod_time));
  148.     disp_status(status, messages);
  149.  
  150.     return 0;
  151. }
  152.  
  153.  
  154. void usage(char *progname)
  155. {
  156.     (void)fprintf(stderr, "Usage: %s printer_name ", progname);
  157.     (void)fprintf(stderr, "[busy | idle | faulted | unavailable]\n");
  158. }
  159.  
  160.  
  161. void disp_opstatus(int status)
  162. {
  163.     (void)printf("\tOperational status:         ");
  164.     switch(status) {
  165.     case PD_STATUS_IDLE:
  166.         (void)printf("IDLE");
  167.         break;
  168.     case PD_STATUS_BUSY:
  169.         (void)printf("BUSY");
  170.         break;
  171.     case PD_STATUS_FAULTED:
  172.         (void)printf("FAULTED");
  173.         break;
  174.     case PD_STATUS_UNAVAILABLE:
  175.         (void)printf("UNAVAILABLE");
  176.         break;
  177.     default:
  178.         (void)printf("UNKNOWN");
  179.         break;
  180.     }
  181.     (void)printf("\n");
  182. }
  183.  
  184.  
  185. void disp_status(PDStatusStruct *status, PDMessageStruct *messages)
  186. {
  187.     register int i;
  188.     char *options;
  189.  
  190.     disp_opstatus(status->operational_status);
  191.     (void)printf("\tMedia type code:            %d\n", status->media_type);
  192.     (void)printf("\tNumber of colors code:      0x%08X\n",
  193.                         status->number_of_colors);
  194.     (void)printf("\t\tNumber of colors:   %d\n",
  195.                 PD_GET_NUMCOLORS(status->number_of_colors));
  196.     disp_colorspace(PD_GET_COLORSPACE_CODE(status->number_of_colors));
  197.     disp_depth(PD_GET_DEPTH_CODE(status->number_of_colors));
  198.     disp_format(PD_GET_FORMAT_CODE(status->number_of_colors));
  199.     (void)printf("\tMedia size code:            0x%08X\n", status->media_size);
  200.     (void)printf("\tMedia size name:            %s\n",
  201.                 PDGetNameBySizeCode(status->media_size));
  202.     options = status->printer_options;
  203.     (void)printf("\tInstalled options:          %s\n",
  204.             (options && *options != '\0') ? options: "None");
  205.     (void)printf("\tMedia size validation mask: %d\n", status->validation_mask);
  206.     (void)printf("\tNumber of messages:         %d\n", status->error_count);
  207.     for (i = 0; i < status->error_count; i++) {
  208.     (void)printf("\n\t\tMessage %d code: 0x%08X\n", i+1,
  209.                     messages[i].message_code);
  210.     (void)printf("\t\tMessage %d text: %s\n", i+1,
  211.                     messages[i].message_text);
  212.     }
  213. }
  214.  
  215.  
  216. void disp_colorspace(int cspace)
  217. {
  218.     (void)printf("\t\tColorspace:         ");
  219.     switch(cspace) {
  220.         case PD_DATA_K:
  221.             (void)printf("k\n");
  222.         break;
  223.         case PD_DATA_CMY:
  224.             (void)printf("cmy\n");
  225.         break;
  226.         case PD_DATA_CMYK:
  227.             (void)printf("cmyk\n");
  228.         break;
  229.         case PD_DATA_W:
  230.             (void)printf("w\n");
  231.         break;
  232.         case PD_DATA_RGB:
  233.             (void)printf("rgb\n");
  234.         break;
  235.         case PD_DATA_YMC:
  236.             (void)printf("ymc\n");
  237.         break;
  238.         case PD_DATA_YMCK:
  239.             (void)printf("ymck\n");
  240.         break;
  241.         case PD_DATA_KCMY:
  242.             (void)printf("kcmy\n");
  243.         break;
  244.     default:
  245.             (void)printf("0x%08X\n", cspace);
  246.         break;
  247.     }
  248. }
  249.  
  250.  
  251. void disp_depth(int depth)
  252. {
  253.     (void)printf("\t\tDepth:              ");
  254.     switch(depth) {
  255.         case PD_DATA_DEPTH1:
  256.             (void)printf("1 bpp\n");
  257.         break;
  258.         case PD_DATA_DEPTH4:
  259.             (void)printf("4 bpp\n");
  260.         break;
  261.         case PD_DATA_DEPTH8:
  262.             (void)printf("8 bpp\n");
  263.         break;
  264.     default:
  265.             (void)printf("0x%08X\n", depth);
  266.         break;
  267.     }
  268. }
  269.  
  270.  
  271. void disp_format(int format)
  272. {
  273.     (void)printf("\t\tFormat:             ");
  274.     switch(format) {
  275.         case PD_DATA_CHUNKY:
  276.             (void)printf("chunky\n");
  277.         break;
  278.         case PD_DATA_BANDED:
  279.             (void)printf("banded\n");
  280.         break;
  281.         case PD_DATA_PLANAR:
  282.             (void)printf("planar\n");
  283.         break;
  284.     default:
  285.             (void)printf("0x%08X\n", format);
  286.         break;
  287.     }
  288. }
  289.